﻿#include "head.h"

using namespace my_namespace;

int main()
{

	map<unsigned int, vector<unsigned int>> best_partition;			// 存放最佳的模块划分结果（模块度最大）
	vector<unsigned int> matrix_order;								// 存放最终的节点编号
	string matrix_filename = "D:/DSM/zchao_CMake_project/examples/颚式破碎机(unweighted).csv";
	//Eigen_Sparse_Matrix eigenSparMatrix(matrix_filename, false, false);
	Eigen_Sparse_Matrix eigenSparMatrix(matrix_filename);
	eigenSparMatrix.CV_plot();
	vector<vector<pair<unsigned int, double>>> edgelist = eigenSparMatrix.sparse_matrix_to_edgelist(true);
	cout << "network desity is " << eigenSparMatrix.get_density() << endl;
	DLouvain_param param = { "examples/nuclear_backbone.txt",		//filename
							"",			//filename_part
							1e-6,		//precision
							1.0,		//gamma
							-1,			//display_level
							true,		//verbose
							false,		//reproducibility	
							false,		//renumbering
							true		//randomized
	};

	Directed_Community c = Directed_Community(	edgelist,					// edgelist
												param.precision,
												param.gamma,
												param.reproducibility,
												param.renumbering,
												param.randomized);

	auto start = std::chrono::high_resolution_clock::now();		// 算法开始执行时间
	int levels = c.run(	best_partition,			// 算法主要操作
						param.verbose,							
						param.display_level,
						param.filename_part);
	auto end = std::chrono::high_resolution_clock::now();		// 算法结束执行时间
	double time_taken = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;


	cerr << "computing communities in: " << std::fixed
		<< time_taken << std::setprecision(9) << " seconds" << endl;	// 输出算法的总执行时间
	cerr << levels << "computed" << endl;
	cerr << "modularity: " << c.modularity() << endl;		// 输出最终的模块度


	c.print_final_result(best_partition);					// 输出模块划分的最终结果
	matrix_order = eigenSparMatrix.rewrite_to_arrange_matrix(best_partition);			// 根据最终的划分结果对矩阵进行重排（将同一模块放在一起）
	eigenSparMatrix.CV_plot();
	//eigenSparMatrix.print_sparse_matrix();
	//eigenSparMatrix.sparse_matrix_to_edgelist(true);
	eigenSparMatrix.write_adjmatrix(matrix_order);					// 将重排后的邻接矩阵写入csv文件


	//// 遗传算法

	 //Directed_Graph* g = new Directed_Graph(edgelist, param.reproducibility, param.renumbering);
	 //Base_Genetic_Algorithm* ga = new Louvain_Init_GA(21, 80, 0, 5, 0.3, 0.7, &c);
	 //ga->run();
	return 0;
}
